namespace ClassyBlog.DomainObjects.Specs.Unit
{
    using System;
    using System.Collections.Generic;

    using Machine.Specifications;

    [Subject(typeof(Page))]
    public class when_page_is_created
    {
        static Page page;

        Because of = () => page = new Page();

        It should_have_id = () => page.Id.ShouldNotEqual(Guid.Empty);
    }

    [Subject(typeof(Page))]
    public class when_page_id_is_set
    {
        static Page page;
        static Guid id;

        Establish context = () =>
        {
            page = new Page();
            id = Guid.NewGuid();
        };

        Because of = () => page.Id = id;

        It should_return_the_same = () => page.Id.ShouldEqual(id);
    }

    [Subject(typeof(Page))]
    public class when_setting_dynamic_property_of_page
    {
        static Page page;
        static dynamic dynamicPage;

        static string property;

        Establish context = () =>
        {
            page = new Page();
            dynamicPage = page;
            dynamicPage.DummyProperty = "DynamicValue";
        };

        Because of = () => property = dynamicPage.DummyProperty;

        It should_be_able_to_get = () => property.ShouldEqual("DynamicValue");
    }

    [Subject(typeof(Page))]
    public class when_getting_regular_property_as_dynamic_property_of_page
    {
        static Page page;
        static dynamic dynamicPage;

        static string property;

        Establish context = () =>
        {
            page = new Page { Title = "What is new in Classy Blog" };
            dynamicPage = page;
        };

        Because of = () => property = dynamicPage.Title;

        It should_be_able_to_get = () =>
            property.ShouldEqual("What is new in Classy Blog");
    }

    [Subject(typeof(Page))]
    public class when_setting_regular_property_as_dynamic_property_of_page
    {
        static Page page;
        static dynamic dynamicPage;

        Establish context = () =>
        {
            page = new Page();
            dynamicPage = page;
        };

        Because of = () => dynamicPage.Title = "What is new in Classy Blog";

        It should_be_able_to_set = () =>
            page.Title.ShouldEqual("What is new in Classy Blog");
    }

    [Subject(typeof(Page))]
    public class when_page_dynamic_property_names_is_accessed
    {
        static Page page;
        static IEnumerable<string> dynamicPropertyNames;

        Establish context = () =>
        {
            page = new Page();
            page.SetDynamicProperty("foo", "bar");
        };

        Because of = () => dynamicPropertyNames = page.DynamicPropertyNames;

        It should_return_from_dynamic_property = () =>
            dynamicPropertyNames.ShouldContain("foo");
    }
}